<?php
   @$prompt=$_POST['prompt'];
   //echo $prompt;
   //认证
   $time = time();
   $auth = md5(''.$time);
   $text = utf8_encode($auth);
   $rawHmac = hash_hmac('sha1', $text, '', true);
   $signature = base64_encode($rawHmac);
   $curl = curl_init();

curl_setopt_array($curl, array(
   CURLOPT_URL => 'https://zwapi.xfyun.cn/api/aippt/create',
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_ENCODING => '',
   CURLOPT_MAXREDIRS => 10,
   CURLOPT_TIMEOUT => 0,
   CURLOPT_FOLLOWLOCATION => true,
   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
   CURLOPT_CUSTOMREQUEST => 'POST',
   CURLOPT_POSTFIELDS =>'
{
    "query": "'.$prompt.'"
    
}',
   CURLOPT_HTTPHEADER => array(
      "appId:018b315f",
      "timestamp: $time",
      "signature: $signature",
      "Content-Type: application/json; charset=utf-8"
   ),
));
if(isset($_POST['prompt'])){
   $response = curl_exec($curl);

   curl_close($curl);
   $sid = json_decode($response)->data->sid;
   header("Location:ppt2.php?sid=$sid");
   //echo $prompt;
}

?>
<h1><center>幻星</center></h1>
<form method='post' action='ppt.php'>
   <center><label>输入文本生成PPT</label><br></center>
   <center><input type="text" name='prompt' value=""></center>
   <center><input type="submit" value="提交"></center>
</form>